﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;
using Microsoft.Phone.Shell;

namespace WPExpenseReportDemo
{
    public partial class PageMain : PhoneApplicationPage
    {
        public static XDocument doc = null;

        public PageMain()
        {
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            doc = XDocument.Load("ER.xml");
            this.lbERs.ItemsSource = from er in doc.Descendants("Report")
                                     select new ExpenseReport
                                     {
                                         ReportID = er.Attributes("id").First().Value,
                                         ReportName = er.Attributes("id").First().Value + " : " + er.Attributes("name").First().Value,
                                         ReportDate = er.Attributes("reportDate").First().Value,
                                         Receipts = null
                                     };

        }

        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            TextBlock tb = sender as TextBlock;
            NavigationService.Navigate(new Uri("/ReportDetail.xaml?reportName=" + tb.Text, UriKind.Relative));
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            this.lbERs.ItemTemplate = (DataTemplate)this.Resources["lbDeleteItems"];

        }


        private void Panorama_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {

            PanoramaItem pi = (PanoramaItem)this.panoMain.SelectedItem;

            if (pi.Name.Equals("piSearch"))
            {
                ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IconUri = new Uri("Images/appbar.check.rest.png", UriKind.Relative);
                ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IconUri = new Uri("Images/appbar.close.rest.png", UriKind.Relative);
            }
            else
            {
                ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IconUri = new Uri("Images/appbar.new.rest.png", UriKind.Relative);
                ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IconUri = new Uri("Images/appbar.delete.rest.png", UriKind.Relative);
            }
        }

        private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }
    }
}